import time
from datetime import datetime

begin_1 = 9*60*60 + 30*60 # 9:30
end_1 = 11*60*60 + 31*60 # 11:31
begin_2 = 13*60*60 # 13:00
end_3 = 15*60*60 + 60 # 13:01

def secondsToTime(seconds):
    hour = int(seconds/3600)
    minute = int((seconds%3600)/60)
    second = int((seconds%3600)%60)
    return "%d:%d:%d" % (hour, minute, second)

def getNextTime():
    now = datetime.now()
    if (now.weekday == 5 or now.weekday == 6):
       print("weekly") 
       return 3600

    now_seconds = now.hour*60*60 + now.minute*60 + now.second
    if (now_seconds >= begin_1 and now_seconds <= end_1) or (now_seconds >= begin_2 and now_seconds <= end_3):
        print("work time")
        next = 6
    elif now_seconds < begin_1:
        next = begin_1 - now_seconds
        print("idle time 1, next=", secondsToTime(next))
    elif now_seconds > end_1 and now_seconds < begin_2:
        next = begin_2 - now_seconds
        print("idle time 2, next=", secondsToTime(next))
    else:
        next = (begin_1 - now_seconds) + 24*3600
        print("idle time 3, next=", secondsToTime(next))

    return next


def formatNumber(o_num):
    number = abs(o_num)

    if number < 1000:
        tmp = '%d' % (number)
    elif number < 10000000:
        tmp = '%.2f万' % (number/10000.0)
    else:
        tmp = '%.3f亿' % (number/100000000.0)

    if o_num < 0:
        return '-' + tmp
    else:
        return '+' + tmp

    return tmp

def isBadStock(code, name):
    if name.endswith('退') or name.startswith('ST') or name.startswith('*ST'):
        return True

    if (code.startswith('8') or code.startswith('4') or code.startswith('688')):
        return True

    return False

def isTypeB(code):
    return code.startswith('9') or code.startswith('2')

def cur_time_short_packet():
    return time.strftime("%H%M%S", time.localtime(time.time()))

def cur_time_short():
    return time.strftime("%H:%M:%S", time.localtime(time.time()))

def cur_time():
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))

def cur_day():
    return time.strftime("%Y-%m-%d", time.localtime(time.time()))
